package com.ruoyi.web.controller.background;

import com.ruoyi.background.domain.AppGradeLevel;
import com.ruoyi.background.service.IAppGradeLevelService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 积分等级Controller
 *
 * @author suus
 * @date 2024-08-25
 */
@RestController
@RequestMapping("/applet/gradeLevel")
public class AppGradeLevelController extends BaseController {
    @Autowired
    private IAppGradeLevelService appGradeLevelService;

    /**
     * 查询积分等级列表
     */
    @PreAuthorize("@ss.hasPermi('applet:gradeLevel:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppGradeLevel appGradeLevel) {
        startPage();
        List<AppGradeLevel> list = appGradeLevelService.selectAppGradeLevelList(appGradeLevel);
        return getDataTable(list);
    }

    /**
     * 导出积分等级列表
     */
    @PreAuthorize("@ss.hasPermi('applet:gradeLevel:export')")
    @Log(title = "积分等级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppGradeLevel appGradeLevel) {
        List<AppGradeLevel> list = appGradeLevelService.selectAppGradeLevelList(appGradeLevel);
        ExcelUtil<AppGradeLevel> util = new ExcelUtil<AppGradeLevel>(AppGradeLevel.class);
        util.exportExcel(response, list, "积分等级数据");
    }

    /**
     * 获取积分等级详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:gradeLevel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appGradeLevelService.selectAppGradeLevelById(id));
    }

    /**
     * 新增积分等级
     */
    @PreAuthorize("@ss.hasPermi('applet:gradeLevel:add')")
    @Log(title = "积分等级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppGradeLevel appGradeLevel) {
        return toAjax(appGradeLevelService.insertAppGradeLevel(appGradeLevel));
    }

    /**
     * 修改积分等级
     */
    @PreAuthorize("@ss.hasPermi('applet:gradeLevel:edit')")
    @Log(title = "积分等级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppGradeLevel appGradeLevel) {
        return toAjax(appGradeLevelService.updateAppGradeLevel(appGradeLevel));
    }

    /**
     * 修改积分等级状态
     */
    @PreAuthorize("@ss.hasPermi('applet:gradeLevel:edit')")
    @Log(title = "积分等级", businessType = BusinessType.UPDATE)
    @GetMapping("/changeStatus/{id}/{type}")
    public AjaxResult changeStatus(@PathVariable Integer type, @PathVariable Long id) {
        return toAjax(appGradeLevelService.changeGradeLevelStatus(id, type));
    }

    /**
     * 删除积分等级
     */
    @PreAuthorize("@ss.hasPermi('applet:gradeLevel:remove')")
    @Log(title = "积分等级", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appGradeLevelService.deleteAppGradeLevelByIds(ids));
    }
}
